package com.mzy.linear_struct.hot100.链表;

import com.sun.org.apache.bcel.internal.generic.SWAP;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @Author: mizy3
 * @Date: 2024/08/06/下午3:28
 * @Description:
 */
public class Pro160相交链表 {


    public ListNode getIntersectionNode2(ListNode headA, ListNode headB) {

        ListNode pA = headA;
        ListNode pB = headB;
        while (pA != pB) {
            pA = pA == null ? headB : pA.next;
            pB = pB == null ? headA : pB.next;
        }

        return pA;
    }

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1, new ListNode(2, new ListNode(3)));
        ListNode listNode1 = new ListNode(3, new ListNode(2, new ListNode(1)));

        new Pro160相交链表().getIntersectionNode2(listNode, listNode1);
    }
}






















